﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;
using Newtonsoft.Json.Linq;

namespace Controller.Helper
{
    public class StatusOrder
    {
        public string StatusID { get; set; }
        public string StatusDescription { get; set; }
    }
    public class DocumentStatus
    {
        public static string GetStatusByRoleJson(string roleName)
        {
            using (DCSalePriceDataContext dataContext = new DCSalePriceDataContext())
            {
                var allStatus = from status in dataContext.tblRoleStatus
                                join detail in dataContext.tblStatus on status.StatusID equals detail.StatusID
                                where status.RoleName.Equals(roleName)
                                select new
                                           {
                                               detail.StatusID,
                                               detail.StatusDescription
                                           };
                var allStatusReoder = new List<StatusOrder>();
                foreach (var status in allStatus)
                {
                    if (status.StatusID == "11")
                    {
                        allStatusReoder.Insert(0, new StatusOrder { StatusID = status.StatusID, StatusDescription = status.StatusDescription });
                    }
                    else if (status.StatusID == "30")
                    {
                        allStatusReoder.Insert(0, new StatusOrder { StatusID = status.StatusID, StatusDescription = status.StatusDescription });
                    }
                    else
                    {
                        allStatusReoder.Add(new StatusOrder { StatusID = status.StatusID, StatusDescription = status.StatusDescription });
                    }
                }
                JObject k = JObject.FromObject(new
                {
                    AllStatus = allStatusReoder
                });
                return k.ToString();
            }
        }
        public static List<tblStatus> GetAllStatus()
        {
            using (DCSalePriceDataContext dataContext = new DCSalePriceDataContext())
            {
                var allStatus = from status in dataContext.tblStatus
                                select status;


                return allStatus.ToList();
            }
        }
    }

    
}
